//注册servlet
package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import mymail.DaoRegister;

public class DoRegister extends HttpServlet {
	public DoRegister() {
		super();
	}
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session=request.getSession();
		String result;
		String username="";
		String password="";
		username=request.getParameter("username");
		password=request.getParameter("password");
		DaoRegister reg=new DaoRegister(username,password);
		try {
					if(reg.add(username, password))
					{
						result="注册成功";
						request.setAttribute("result", result);
						request.getRequestDispatcher("index.jsp").forward(request, response);
						//response.sendRedirect("/Mail/index.jsp");
					}
					else
					{
						result ="注册失败，请重新注册";
						request.setAttribute("result", result);
						request.getRequestDispatcher("register.jsp").forward(request, response);
						//response.sendRedirect("/Mail/register.html");
					}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//response.sendRedirect("/Mail/index.jsp");
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	}
	public void init() throws ServletException {
		// Put your code here
	}

}
